package com.homedo.microservice.open.service.gateway.alert.gateway.persistence.dao;

import com.homedo.common.bean.vo.Pagination;
import com.homedo.common.dao.BaseDao;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.alert.gateway.bean.po.RouteServiceUrl;
import com.homedo.microservice.open.service.gateway.alert.gateway.bean.query.RouteServiceUrlQuery;
import com.homedo.microservice.open.service.gateway.alert.gateway.persistence.mapper.IRouteServiceUrlMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月18日 11时30分20秒
 */
@Repository
public class RouteServiceUrlDao extends BaseDao<RouteServiceUrl> {
    @Autowired
    private IRouteServiceUrlMapper routeServiceUrlMapper;

    public List<RouteServiceUrl> getListByServiceIds(List<String> serviceIds) {
        Example example = new Example(RouteServiceUrl.class);
        example.createCriteria().andIn(RouteServiceUrl.FIELD_SERVICEID, serviceIds);
        example.setOrderByClause(RouteServiceUrl.ORDER_CREATE_TIME_DESC);

        return super.getListByExample(example);
    }

    public Pagination<RouteServiceUrl> getPagination(RouteServiceUrlQuery routeServiceUrlQuery, Pagination<RouteServiceUrl> pagination) {
        Example example = new Example(RouteServiceUrl.class);
        Example.Criteria criteria = example.createCriteria();

        if (Detect.notEmpty(routeServiceUrlQuery.getStatuses())) {
            criteria.andIn(RouteServiceUrl.FIELD_STATUS, routeServiceUrlQuery.getStatuses());
        }

        if (Detect.notEmpty(routeServiceUrlQuery.getServiceIds())) {
            criteria.andIn(RouteServiceUrl.FIELD_SERVICEID, routeServiceUrlQuery.getServiceIds());
        }

        return super.getPagination(pagination, example);
    }
}
